package cn.zhangjie.system.service.impl;

import cn.zhangjie.basic.service.imp.BasicServiceImpl;
import cn.zhangjie.system.domain.Role;
import cn.zhangjie.system.mapper.RoleMapper;
import cn.zhangjie.system.service.IRoleService;
import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class RoleServiceImpl extends BasicServiceImpl<Role> implements IRoleService {


    @Autowired
    private RoleMapper roleMapper;

    @Override
    public void update(Role role) {
        roleMapper.update(role);
        roleMapper.removeRoleMenu(role.getId());
        roleMapper.removeRolePermission(role.getId());

        // 添加t_role_permission
        roleMapper.saveRolePermission(role.getId(),role.getPermissions());
        // 添加t_role_menu
        roleMapper.saveRoleMenu(role.getId(),role.getMenus());

    }







    @Override
    public void add(Role role) {
        // 三张表   role(返回自增的id)
        roleMapper.save(role);

        // 添加t_role_permission
        roleMapper.saveRolePermission(role.getId(),role.getPermissions());
        // 添加t_role_menu
        roleMapper.saveRoleMenu(role.getId(),role.getMenus());



    }

    @Override
    public void del(Long rid) {
        // 删除 ， 先删除关联表，再删除自己

        roleMapper.removeEmployeeRole(rid);
        roleMapper.removeRoleMenu(rid);
        roleMapper.removeRolePermission(rid);

        // 删除自己
        roleMapper.remove(rid);

    }



}
